define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                    items: [],
                    store:{},
                    loading:0,
                    title:'',
                    page:1,
                    lastpage:0,
                    commission_money:'',
                    keyword:''
                    
                };
            },
            el: '#pageMemberList',
            created: function() {
                this.fetchData();
            },
            mounted: function() {
                    // console.log("123");
                    if (this.mounted == 1) {
                        return;
                    }
                    
                    var that = this ;
                    app.pager("#pageMemberList",function(){
                       that.getList();
                    });
                    this.mounted = 1;

            },
            methods: {
                fetchData: function() {
                    var _this = this;
                    this.getList();
                },
                 
              
               pageShow:function(){
                    
                },
                search:function(event){
                  this.keyword = $("#keyword").val();

                  this.getList(1);
                },
              
              userDetail:function(user_id){
                 var user_info = app.getUserInfo();
                 var params=[
                  {
                      'text':'等级设置',
                      'methods':function(){
                          app.colseHandle();
                          window.location.href=app.params.apiDomain+"admin/system-member/user_tag?user_id="+user_id+"&store_id="+app.getStoreId()+"&token="+user_info.token;
                          
                      }
                    },
                    {
                      'text':'修改信息',
                      'methods':function(){
                           app.colseHandle();
                            window.location.href=app.params.apiDomain+"admin/system-member/add?user_id="+user_id+"&store_id="+app.getStoreId()+"&token="+user_info.token;

                           // that.$router.push({ name: 'addMemberCard', params: { id: card_id,appid:appid } });
                      }
                    }
                    
                    
                  ];
                  app.handle(params);
                },
                 
             getList:function(reload){
                    var that = this;
                     if(reload==1){
                       that.loading=0;
                       that.lastpage=0;
                       that.items=[];
                       that.page=1;
                     }
                    if( that.loading == 1 || that.lastpage==1){
                        return ;
                     }

                     that.loading = 1;
                     
                    app.get("apiv2/wx_card_user/get", {
                      card_id : that.$route.params.card_id,
                      keyword:that.keyword,
                      limit:50,
                      page:that.page
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      if (res.data.list.length === 0) {
                        that.lastpage = 1;
                      }
                      that.page++;
                      that.items = that.items.concat(res.data.list); 
                    });
                }
                
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
